package day05;

import java.util.Arrays;

public class ArrayDemo {
    public static void main(String[] args) {
        int[] arr = new int[3];
        System.out.println("长度为："+arr.length);//3
        System.out.println("第一个元素为："+arr[0]);//默认值：0

        arr[0] = 120;
        arr[1] = 100;
        arr[2] = 80;

        System.out.println("第一个元素为："+arr[0]);//120
        System.out.println("第二个元素为："+arr[1]);//100
        System.out.println("最后一个元素为："+arr[2]);//80
        System.out.println("最后一个元素为："+arr[arr.length-1]);//80

        int[] arr1 = new int[10];
        for(int i =0;i< arr1.length;i++){
            arr1[i] = (int)(Math.random()*100);
            System.out.print("第"+(i+1)+"个元素为："+arr1[i]+"\t");
        }

        int[] arr2 = new int[]{12,4,7,8,9};
        int[] copyArr = Arrays.copyOf(arr2,arr2.length);
        int[] copyArr1 = Arrays.copyOf(arr2,arr2.length-1);
        int[] copyArr2 = Arrays.copyOf(arr2,arr2.length+1);
        System.out.println("\n数组1：");
        for (int i = 0; i < copyArr.length; i++) {
            System.out.print(copyArr[i]+" ");
        }
        System.out.println("\n数组2：");
        for (int i = 0; i < copyArr1.length; i++) {
            System.out.print(copyArr1[i]+" ");
        }
        System.out.println("\n数组3：");
        for (int i = 0; i < copyArr2.length; i++) {
            System.out.print(copyArr2[i]+" ");
        }


    }
}
